<?php

namespace App\Http\Requests;

use Auth;
use App\Admin;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class UpdateAdmin extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
         return Auth::user()->can('update',$this->route('admin'));
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'name'     => 'required|max:10',
            'email'    => ['required', 'email', Rule::unique('admins')->ignore($this->route('admin.id'))],
            'password' => 'string'
        ];
    }
}
